﻿#ifndef PAGENAVIGATOR_H
#define PAGENAVIGATOR_H

#include <QtWidgets/QLabel>
#include <QtWidgets/QWidget>
#include "ui_pagenavigator.h"

namespace Ui
{
    class PageNavigator;
}

class PageNavigator : public QWidget
{
    Q_OBJECT

public:
    explicit PageNavigator(int pageSize = 3, QWidget *parent = nullptr);
    ~PageNavigator();

    int getCurrentPage() const;

    // 其他组件只需要调用这些函数即可
    void setTotalNum(int totalnum); //总条数
    void setCurrentPage(int page, bool signalEmitted = false); // 修改当前页时调用
protected:
    virtual bool eventFilter(QObject *watched, QEvent *e);

signals:
    void currentPageChanged(int page);
private:
    int getPageNum() const;
    int getMaxPage() const;

    void setMaxPage(int page);   // 当总页数改变时调用

private:
    Ui::PageNavigator ui;
    int m_pageSize;
    int m_maxPage;
    int m_currentPage;

    void setPageSize(int blockSize);
    void updatePageLabels();
    void initialize();
};

#endif // PAGENAVIGATOR_H
